from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime

class ChatSessionCreate(BaseModel):
    """创建会话"""
    title: str
    knowledge_base_id: Optional[str] = None

class ChatSessionResponse(BaseModel):
    """会话响应"""
    id: str
    title: str
    knowledge_base_id: Optional[str]
    created_at: datetime
    message_count: int = 0
    
    class Config:
        from_attributes = True

class ChatMessageResponse(BaseModel):
    """消息响应"""
    id: str
    session_id: str
    role: str
    content: str
    sources: Optional[List[dict]] = []
    created_at: datetime
    
    class Config:
        from_attributes = True

class ChatRequest(BaseModel):
    """聊天请求"""
    message: str
    session_id: Optional[str] = None
    knowledge_base_id: Optional[str] = None
    document_ids: Optional[str] = None  # 逗号分隔的文档ID列表
    temperature: float = 0.7
    max_tokens: int = 2000
    stream: bool = True

class ChatResponse(BaseModel):
    """聊天响应"""
    message: str
    session_id: str
    sources: Optional[List[dict]] = []

